package com.vtuzx.kingdee.xqc_core.service;

import com.vtuzx.core.VtuzxException;
import com.vtuzx.core.bean.dto.VtuzxMap;
import com.vtuzx.kingdee.xqc_core.bean.kingdee.KingdeeAccount;
import com.vtuzx.kingdee.xqc_core.bean.kingdee.VtuzxKingdeeCloudClient;
import org.bson.types.ObjectId;

import java.util.List;
import java.util.Map;

/**
 * 金蝶服务
 */
public interface IVtuzxKingdeeService {

    /**
     * 获取金蝶账号信息
     *
     * @return 金蝶账号信息
     */
    KingdeeAccount getAccount();

    /**
     * 金蝶登录
     *
     * @return 登录结果
     * @throws VtuzxException 登录异常
     */
    VtuzxKingdeeCloudClient loginKingdee() throws VtuzxException;

    /**
     * 金蝶登录
     *
     * @return 登录结果
     * @throws VtuzxException 登录异常
     */
    VtuzxKingdeeCloudClient loginKingdeeYeXiang() throws VtuzxException;

    /**
     * 金蝶登录
     *
     * @return 登录结果
     * @throws VtuzxException 登录异常
     */
    VtuzxKingdeeCloudClient loginKingdeeYX() throws VtuzxException;

    /**
     * 保存单据
     *
     * @return 处理结果
     * @throws Exception 异常
     */
    List<VtuzxMap> save(VtuzxKingdeeCloudClient client, String formId, VtuzxMap param) throws Exception;
    /**
     * 保存单据
     *
     * @return 处理结果
     * @throws Exception 异常
     */
    List<VtuzxMap> save(VtuzxKingdeeCloudClient client, String formId, Map<String, Object> param) throws Exception;

    /**
     * 下推单据
     *
     * @return 领料单列表
     * @throws Exception 异常
     */
    List<VtuzxMap> push(VtuzxKingdeeCloudClient client, String formId, VtuzxMap param) throws Exception;
    /**
     * 下推单据
     *
     * @return 领料单列表
     * @throws Exception 异常
     */
    List<VtuzxMap> push(VtuzxKingdeeCloudClient client, String formId, Map<String, Object> param) throws Exception;

    /**
     * 单据提交
     *
     * @param formId 表单ID
     * @param orgId 组织ID
     * @param billNo 单据号
     * @return 查询结果
     * @throws VtuzxException 异常
     */
    List<VtuzxMap> submit(VtuzxKingdeeCloudClient client, String formId, String orgId, String billNo) throws VtuzxException;

    /**
     * 单据审核
     *
     * @param formId 表单ID
     * @param orgId 组织ID
     * @param billNo 单据号
     * @return 查询结果
     * @throws VtuzxException 异常
     */
    List<VtuzxMap> audit(VtuzxKingdeeCloudClient client, String formId, String orgId, String billNo) throws VtuzxException;

    /**
     * 单据审核
     *
     * @param formId 表单ID
     * @param orgId 组织ID
     * @param billNo 单据号
     * @param interationFlags 交互标志集合
     * @return 查询结果
     * @throws VtuzxException 异常
     */
    List<VtuzxMap> audit(VtuzxKingdeeCloudClient client, String formId, String orgId, String billNo, String interationFlags) throws VtuzxException;


    /**
     * 单据下达
     *
     * @param formId 表单ID
     * @param orgId 组织ID
     * @param billNo 单据号
     * @return 查询结果
     * @throws VtuzxException 异常
     */
    List<VtuzxMap> toRelease(VtuzxKingdeeCloudClient client, String formId, String status, String orgId, String billNo) throws VtuzxException;


    /**
     * 单据下达
     *
     * @param formId 表单ID
     * @param orgId 组织ID
     * @param billNo 单据号
     * @param interationFlags 交互标志集合
     * @return 查询结果
     * @throws VtuzxException 异常
     */
    List<VtuzxMap> toRelease(VtuzxKingdeeCloudClient client, String formId, String status, String orgId, String billNo, String interationFlags) throws VtuzxException;


    /**
     * 单据添加附件
     *
     * @param client 客户端
     * @param type 类型
     * @param fId 数据Fid
     * @param fNumber 数据FNumber
     * @param fileId 文件ID
     * @param fileName 文件名
     * @param fileSize 文件大小
     * @param ext 文件扩展名
     * @param allowDownload 是否允许下载
     * @return 处理结果
     * @throws Exception 异常
     */
    List<VtuzxMap> saveAttachment(VtuzxKingdeeCloudClient client, String type, String fId, String fNumber, String fileId, String fileName, int fileSize, String ext, boolean allowDownload) throws Exception;

    /**
     * 查询单据
     *
     * @param client 客户端
     * @param formId 表单ID
     * @param fieldList 字段列表
     * @param cond 条件
     * @return 处理结果
     * @throws Exception 异常
     */
    default List<VtuzxMap> query(VtuzxKingdeeCloudClient client, String formId, List<String> fieldList, String cond) throws Exception {
        return query(client, formId, fieldList, cond, null, 0, 0);
    }

    /**
     * 查询单据
     *
     * @param client 客户端
     * @param formId 表单ID
     * @param fieldList 字段列表
     * @param cond 条件
     * @param order 排序
     * @param start 开始字段
     * @param limit 限制条数
     * @return 处理结果
     * @throws Exception 异常
     */
    List<VtuzxMap> query(VtuzxKingdeeCloudClient client, String formId, List<String> fieldList, String cond, String order, int start, int limit) throws Exception;

    VtuzxMap getConfig();

    /**
     * 修改生产订单下达时间
     * @param client
     * @param formId
     * @param billNo
     * @param updateTime
     * @return
     */
    int orderUpdate(VtuzxKingdeeCloudClient client,String formId,String billNo,String updateTime) throws VtuzxException;


    /**
     * 根据当前用户名登录
     * @param userId
     * @param name
     * @return
     * @throws VtuzxException
     */
    VtuzxKingdeeCloudClient loginKingdeeEveryClient(ObjectId userId, String name) throws VtuzxException;;
}
